#include "timerdialog.h"
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QMessageBox>


TimerDialog::TimerDialog():m_counter(0)
{
    m_label = new QLabel("timer: 0", this);
    m_setButton = new QPushButton("set", this);
    m_stopButton = new QPushButton("stop", this);
    m_timerValue = new QLineEdit("300", this);

    setLayout(new QVBoxLayout);

    QHBoxLayout* hl = new QHBoxLayout();

    layout() -> addWidget(m_label);
    hl ->  addWidget(m_timerValue);
    hl -> addWidget(m_setButton);
    layout() -> addItem(hl);
    layout() -> addWidget(m_stopButton);

    connect(m_setButton, SIGNAL(clicked()), this, SLOT(setTimer()));
    connect(m_stopButton, SIGNAL(clicked()), this, SLOT(stopTimer()));
}

void TimerDialog::timerEvent(QTimerEvent *te)
{
    m_counter++;
    m_label -> setText("timer: " + QString::number(m_counter));
}

void TimerDialog::setTimer()
{
    killTimer(m_timerId1);
    m_timerId1 = startTimer(m_timerValue->text().toInt());
}

void TimerDialog::stopTimer()
{
    killTimer(m_timerId1);
}
